/*********************************************************
 *  Copyright (c) 2011 by Web Information Systems (WIS) Group, 
 *  Delft University of Technology.
 *  Qi Gao, http://wis.ewi.tudelft.nl/index.php/home-qi-gao
 *  
 *  Some rights reserved.
 *
 *  Contact: q.gao@tudelft.nl
 *
 **********************************************************/
package org.persweb.genius.model;

import java.net.URI;

/**
 * @author Qi Gao <a href="mailto:q.gao@tudelft.nl">q.gao@tudelft.nl</a>
 * @version created on Jul 1, 2011 10:49:35 AM
 */
public class ConceptImpl implements Concept {

	private String type = null;
	private String name = null;
	private URI uri = null;

	/**
	 * 
	 */
	public ConceptImpl() {
		super();
	}

	/**
	 * @param uri
	 */
	public ConceptImpl(URI uri) {
		super();
		this.uri = uri;
	}
	
	/**
	 * @param name
	 */
	public ConceptImpl(String name) {
		super();
		this.name = name;
	}

	/**
	 * 
	 * @param id
	 * @param name
	 * @param uri
	 */
	public ConceptImpl(String type, String name, URI uri) {
		super();
		this.type = type;
		this.name = name;
		this.uri = uri;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#getType()
	 */
	@Override
	public String getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#getUri()
	 */
	@Override
	public URI getUri() {
		return uri;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#setString(java.lang.String)
	 */
	@Override
	public void setType(String type) {
		this.type = type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#setName(java.lang.Object)
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.persweb.genius.model.Concept#setUri(java.lang.Object)
	 */
	@Override
	public void setUri(URI uri) {
		this.uri = uri;
	}

	public int hashCode() {
		if (this.uri != null && this.name != null) {
			return (this.uri + this.name).hashCode();
		} else if (this.uri != null && this.name == null) {
			return this.uri.hashCode();
		} else if (this.uri == null && this.name != null) {
			return this.name.hashCode();
		}
		return super.hashCode();
	}

	public boolean equals(Object o){
		if (o instanceof ConceptImpl &&
				((ConceptImpl) o).getUri() != null &&
				this.uri != null && ((ConceptImpl) o).getName() == null && this.name == null) {
			return this.uri.equals(((ConceptImpl) o).getUri());
		} else if (o instanceof ConceptImpl &&
				((ConceptImpl) o).getUri() == null &&
				this.uri == null && ((ConceptImpl) o).getName() != null && this.name != null) {
			return this.name.equals(((ConceptImpl) o).getName());
		} else if (o instanceof ConceptImpl &&
				((ConceptImpl) o).getUri() != null &&
				this.uri != null && ((ConceptImpl) o).getName() != null && this.name != null) {
			return this.name.equals(((ConceptImpl) o).getName()) && this.uri.equals(((ConceptImpl) o).getUri());
		} else {
			return false;
		}
	}

	@Override
	public String toString() {
		return "String-based Concept [ID=" + type + ", name=" + name + ", uri="
				+ uri + "]";
	}

}
